package cn.initcap.algorithm.swing.sort.heap;

/**
 * @author initcap
 * @date 2018/8/3 AM10:47
 */
public class HeapSortData {

    /**
     * numbers[heapIndex...N) 已经排好序
     */
    public int heapIndex;
    private int[] numbers;

    public HeapSortData(int n, int randomBound) {

        numbers = new int[n];
        heapIndex = n;

        for (int i = 0; i < n; i++) {
            numbers[i] = (int) (Math.random() * randomBound) + 1;
        }
    }

    public int N() {
        return numbers.length;
    }

    public int get(int index) {
        if (index < 0 || index >= numbers.length) {
            throw new IllegalArgumentException("Invalid index to access Sort Data.");
        }
        return numbers[index];
    }

    public void swap(int i, int j) {

        if (i < 0 || i >= numbers.length || j < 0 || j >= numbers.length) {
            throw new IllegalArgumentException("Invalid index to access Sort Data.");
        }
        int t = numbers[i];
        numbers[i] = numbers[j];
        numbers[j] = t;
    }
}